var MainApp = function(){
	return{
		search : function(){
			var url = $("#APP_ROOT_PATH").val() +  "goods/page?serach="+$("#goodsName").val(); 
			location.href = url;
			return false;
		},
		
		//优惠券
		getCouponData:function(){
			var pCount = 0;
			var url = $("#APP_ROOT_PATH").val() + "coupon/page_data";

			mui.util.Ajax.asyncGET(url, {
				"pageSize" : 10,
			}, function(data) {
				layer.closeAll();
				if (data) {
					pCount = data.total;
					var jsonData = {
						"data" : data.rows
					};
					var bt = baidu.template;
					var htmlStr = bt('t:couponM', jsonData);
					$(".couponM").html(htmlStr);
					
					var mySwiper = new Swiper ('.coupon .swiper-container', {
	                pagination: '.coupon  .swiper-pagination',
	                slidesPerView: 'auto',
	                centeredSlides: false,
	                paginationClickable: true,
	                spaceBetween: 10
	            });
					
					
				}
			}, function() {
				layer.closeAll();
			}, function() {
			})
		},
		alreadyGet:function(){
			layer.open({
			    content: '您已经领取过优惠券了',
			    skin: 'msg',
			    time: 2 //2秒后自动关闭
			 });
		},
			
		//领取优惠券
		getCouponValue:function(couponId){
			var url = $("#APP_ROOT_PATH").val() + "coupon/get_data";
			mui.util.Ajax.asyncGET(url, {
				"couponId" : couponId
			}, function(res) {
				if(res.ret != undefined && res.ret != 0){
					layer.open({
					    content: res.message,
					    skin: 'msg',
					    time: 2 //2秒后自动关闭
					 });
					return;
				}
				
				if (res > 1) {
					layer.open({
					    content: '领取成功',
					    skin: 'msg',
					    time: 2 //2秒后自动关闭
					 });
					window.history.go(-1);
				}
			}, function() {
				
			}, function() {
				
			})
		},
		
		//砍价活动
		getDiscount : function(){
			var pageIndex = 0; // 页面索引初始值
			var pageSize = 2; // 每页显示条数初始化，修改显示条数，修改这里即可
			var pCount = 0;
			var url = $("#APP_ROOT_PATH").val() + "discount/page_data";

			mui.util.Ajax.asyncGET(url, {
				"pageSize" : pageSize,
			}, function(data) {
				layer.closeAll();
				if (data) {
					pCount = data.total;
					var jsonData = {
						"data" : data.rows
					};
					var bt = baidu.template;
					var htmlStr = bt('t:kanjia', jsonData);
					$(".kanjia").before(htmlStr);
				}
			}, function() {
				layer.closeAll();
			}, function() {
				setTimeout(function() {
					layer.closeAll('loading');
				}, 1000)
			})
		},
		
		
		
		//热卖商品
		getHotGoods : function(){
			var pageIndex = 0; // 页面索引初始值
			var pCount = 0;
			var url = $("#APP_ROOT_PATH").val() + "advert/page_data";
			mui.util.Ajax.asyncGET(url, null, function(data) {
				layer.closeAll();
				if (data.length > 0) {
					
					var jsonData = {
						"data" : data
					};
					var bt = baidu.template;
					var htmlStr = bt('t:hotgoods', jsonData);
					$(".hotgoods").html(htmlStr);
				}
			}, function() {
				layer.closeAll();
			}, function() {
				setTimeout(function() {
					layer.closeAll('loading');
				}, 1000)
			})
			
		},
	}
}();